{{include template('public/header','admin')}}
</head>
<body>
    <div class="container">
        <div style="margin: 20px;">
            <form class="form-horizontal" role="form" action="{{url($postUrl)}}" method="post"  id="cpform" name="cpform"  onsubmit="return dosub(this)" >
                <input type='hidden' name='modelid' value="{{$item['modelid']}}" />
                <input type='hidden' name='disabled' value="1" />
                <div class="form-group">
                    <label for="name" class="col-sm-2 control-label">表单名称</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="name" name="name"  value="{{$item['name']}}" placeholder="请输入表单名称"  onblur="tickycms_pinyin()"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="tablename" class="col-sm-2 control-label">表名</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="tablename" name="tablename"  value="{{$item['tablename']}}" placeholder="请输入表名"  {{if $action eq '修改'}}disabled="disabled"{{/if}} >
                    </div>
                </div>
                <div class="form-group">
                    <label for="check_code" class="col-sm-2 control-label">开启验证码</label>
                    <div class="col-sm-10">
                        <label class="radio-inline">
                            <input type="radio" name="check_code" id="check_code1" value="1"  {{if $item.check_code eq '1'}}checked{{/if}} > 是
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="check_code" id="check_code2" value="0" {{if $item.check_code eq '0'}}checked{{/if}}> 否
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label for="allowvisitor" class="col-sm-2 control-label">允许游客提交</label>
                    <div class="col-sm-10">
                        <label class="radio-inline">
                            <input type="radio" name="allowvisitor" id="check_code1" value="1"  {{if $item.allowvisitor eq '1'}}checked{{/if}}> 是
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="allowvisitor" id="check_code2" value="0"  {{if $item.allowvisitor eq '0'}}checked{{/if}}> 否
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label for="description" class="col-sm-2 control-label">表单简介</label>
                    <div class="col-sm-10">
                        <textarea name="description" class="form-control">{{$item['description']}}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label for="show_template" class="col-sm-2 control-label">显示页模板</label>
                    <div class="col-sm-10">
                        <select id="show_template" name="show_template"  class="form-control">
                            <option value="">请选择</option>
                            {{foreach $show_temp as $key=>$val }}
                            <option {{if $item["show_template"] eq $key}}selected{{/if}} value="{{$key}}">{{$val}}({{$key}})</option>
                            {{/foreach}}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <input type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" class="btn btn-primary "/>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script type="text/javascript" src="{{STATIC_URL}}/plugins/pinyin.js"></script>

    <script type="text/javascript">
                            function tickycms_pinyin() {
                                var pinyin = codefans_net_CC2PY($("input[name='name']").val());
                                $("input[name='tablename']").val(pinyin.toLowerCase());
                            }
                            function dosub(obj) {
                                var reg = /^[A-Za-z]+$/;
                                if (obj.name.value == '') {
                                    layer.msg('表单名称不能为空！');
                                    return false;
                                }
                                if (obj.tablename.value == '') {
                                    layer.msg('表名不能为空！');
                                    return false;
                                }
                                if (!reg.test(obj.tablename.value)) {
                                    layer.msg('表名只能为英文或拼音！');
                                    return false;
                                }

                                if ($("select[name='list_template']").val() == '') {
                                    layer.msg('请选择列表页模板！');
                                    return false;
                                }
                                if ($("select[name='show_template']").val() == '') {
                                    layer.msg('请选择显示页模板！');
                                    return false;
                                }

                                $.ajax({
                                    type: 'POST',
                                    url: '{{url($postUrl)}}',
                                    data: $(obj).serialize(),
                                    dataType: "json",
                                    success: function (ret) {
                                        if (ret.status=="y") {
                                            parent.location.reload();
                                        } else {
                                            layer.msg(ret.info);
                                        }
                                    }
                                });
                                return false;
                            }
    </script>
</body>
</html>